<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商品信息列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
<!--                            <label>品牌名称：</label>-->
<!--                            <select name="firmString" id="firm">-->
<!--                                <option  value="">请选择</option>-->
<!--                            </select>-->
                            <div class="col-sm-8">
                                <select name="poBrandId" class="form-control m-b">
                                    <option value="">请选择</option>
                                    <option th:each="brand : ${brandList}" th:value="${brand.brandId}" th:text="${brand.brandName}"></option>
                                    </select>
                            </div>
                        </li>
                        <li>
<!--                            <label>商品类型：</label>-->
<!--                            <select name="TypeString" id="type">-->
<!--                                <option  value="">请选择</option>-->
<!--                            </select>-->
                            <div class="col-sm-8">
                                <select name="poTypeId" class="form-control m-b">
                                    <option value="">请选择</option>
                                    <option th:each="type : ${typeList}" th:value="${type.typeId}" th:text="${type.typeName}"></option>
                                </select>
                            </div>
                        </li>
                        <li>
                            <label>商品型号：</label>
                            <input type="text" name="productModel"/>
                        </li>
                        <li>
                            <label>状态：</label>
                            <select name="status">
                                <option value="">请选择</option>
                                <option value="1">可用</option>
                                <option value="0">不可用</option>
                            </select>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="purchase:product:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="purchase:product:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="purchase:product:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="purchase:product:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('purchase:product:edit')}]];
    var removeFlag = [[${@permission.hasPermi('purchase:product:remove')}]];
    var detailFlag = [[${@permission.hasPermi('purchase:product:detail')}]];
    var prefix = ctx + "purchase/product";

    $(function() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            detailUrl: prefix + "/detail/{id}",
            modalName: "商品信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'productId',
                    title: '商品id',
                    visible: false
                },
                {
                    title: "序号",
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field: 'productModel',
                    title: '商品型号'
                },
                {
                    field: 'brand.brandName',
                    title: '品牌名称'
                },
                {
                    field: 'type.typeName',
                    title: '商品类型'
                },
                {
                    field: 'unit',
                    title: '单位'
                },
                {
                    field: 'price',
                    title: '单价',
                    formatter: function (value){
                        return "￥"+value;
                    }
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '用户状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'sysUser.userName',
                    title: '创建人'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.productId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.productId  + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.productId  + '\')"><i class="fa fa-search"></i>详细</a>');
                        return actions.join('');
                    }
                }]
        };

        $.table.init(options);
    });

    /* 用户状态显示 */
    function statusTools(row) {
        if (row.status == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.productId  + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.productId  + '\')"></i> ';
        }
    }

    /* 用户管理-停用 */
    function disable(productId ) {
        $.modal.confirm("确认要停用用户吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "productId": productId , "status": 0 });
        })
    }

    /* 用户管理启用 */
    function enable(productId ) {
        $.modal.confirm("确认要启用用户吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "productId": productId , "status": 1 });
        })
    }

    $(document).ready(function() {   //页面加载时运行此函数  放在最前端
        $.get("/purchase/product/firm/select",{},function(data){
            <!--清空下拉框中的缓存-->
            $("#firm").empty();
            <!--避免下拉框的值不变-->
            $("#firm").append("<option value=''>请选择</option>");
            <!--使用循环解析后端传来的数据，并用使用js动态拼接html语言-->
            for (var i = 0; i < data.length; i++) {
                $("#firm").append("<option value='" + data[i].poFirmId + "'>" + data[i].firmName + "</option>");
            }
        })
    })

    // $(document).ready(function() {   //页面加载时运行此函数  放在最前端
    //     $.get("/purchase/product/type/select",{},function(data){
    //         <!--清空下拉框中的缓存-->
    //         $("#type").empty();
    //         <!--避免下拉框的值不变-->
    //         $("#type").append("<option value=''>请选择</option>");
    //         <!--使用循环解析后端传来的数据，并用使用js动态拼接html语言-->
    //         for (var i = 0; i < data.length; i++) {
    //             $("#type").append("<option value='" + data[i].poTypeId + "'>" + data[i].typeName + "</option>");
    //         }
    //     })
    // })




</script>
</body>
</html>